
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_read_request = binder_py('mx_eyelink_read_request')
eyelink_read_request.mx_c.headers = ['<eyelink.h>','"mex.h"']
eyelink_read_request.bindo += []
eyelink_read_request.mx_c.code = \
"""
INT16 _main( char FARTYPE *msg )
{
    return eyelink_read_request( msg );
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    char FARTYPE *msg;

    /* Verify input arguments. */
    if(nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
           
    if ( !mxIsChar(prhs[0]) )
        mexErrMsgTxt("msg should be a string.");

    msg = mxArrayToString(prhs[0]);

    if ( msg == NULL )
	mexErrMsgTxt("msg could not be read.");
    
    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);
    
    *status = (double ) _main( msg );

    mxFree(msg);

    return;
}
"""

eyelink_read_request.mx_c.mdoc = \
"""function [ ] = mx_eyelink_read_request( )
%MX_EYELINK_READ_REQUEST Sends a text variable name whose value is to be read 
% and returned by the tracker as a text string.
%
% Remarks:
% NEW (v2.1): If the link is initialized but not connected to a tracker, the 
% message will be sent to the tracker set by set_eyelink_address(). However, 
% these requests will be ignored by tracker versions older than EyeLink I v2.1
% and EyeLink II v1.1.
% Parameters:
% text 	String with message to send.
% Returns:
% 0 if success, otherwise link error code.
%
"""
eyelink_read_request.write_c()
eyelink_read_request.write_m()
eyelink_read_request.compile()
eyelink_read_request.write_sh()

